#include<bits/stdc++.h>
using namespace std;
#define pc putchar
#define pb push_back
#define mp make_pair
#define ls (id<<1)
#define rs ((id<<1)|1)
#define mid ((l+r)>>1)
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
char buf[(1<<21)+5],*p1,*p2;
#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

int read(){
    int ret=0,f=0; char ch=gc();
    while(ch<'0'||ch>'9') f|=(ch=='-'),ch=gc();
    while(ch>='0'&&ch<='9') ret=(ret<<1)+(ret<<3)+(ch^48),ch=gc();
    return f?-ret:ret;
}

void write(int x){
    if(!x) return pc('0'),void();
    if(x<0) pc('-'),x=-x;
    int stk[30],tp=0;
    while(x) stk[++tp]=x%10,x/=10;
    while(tp) pc('0'+stk[tp--]);
    return;
}

const int Maxn=1e6+10,INF=1e9+7;
int N,K,Q,A[Maxn],x[Maxn],L[Maxn],R[Maxn],Ans;
bool f;

void Solve(int l,int r,int v,int num){
    if(l==1&&r==N) return Ans+=num,void();
    if(l!=1&&A[l-1]<=v) Solve(l-1,r,v,num+1);
    else if(r!=N&&A[r+1]<=v) Solve(l,r+1,v,num+1);
    else Solve(l,r,min(A[l-1],A[r+1]),num+K);
}

int main(){
    freopen("summer.in","r",stdin);
    freopen("summer.out","w",stdout);
    N=read(),K=read(); For(i,1,N) A[i]=read();
    A[0]=A[N+1]=INF;
    Q=read(); 
    For(i,1,Q){
        x[i]=read(),L[i]=read(),R[i]=read();
        if(i>1&&x[i]!=x[i-1]) f=1;
    }
    // if(f) Solve1(),exit(0);
    For(i,1,Q){
        Ans=0;
        swap(A[x[i]],A[x[i]+1]);
        For(j,L[i],R[i]) Solve(j,j,A[j],0);
        write(Ans),pc('\n');
    }
    return 0;
}